using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace RandomRat {

	/// <summary>
	/// Summary description for CriteriaSelector.
	/// </summary>
	public class CriteriaSelector : System.Windows.Forms.Form {

		private System.Windows.Forms.Button butCancel;
		private System.Windows.Forms.Button butOK;
		private RandomRat.CriteriaSummaryControl criteriaSummaryControl1;
		private System.ComponentModel.Container components = null;

		public CriteriaSelector(DataManager dataManager, Form1 form1) {
			InitializeComponent();
			criteriaSummaryControl1.LoadData(dataManager);
			criteriaSummaryControl1.SetForm1(form1);

			if (criteriaSummaryControl1.listBox1.Items.Count == 0) {
				butOK.Enabled = false;
			}
		}

		public string SelectedCritieriaID {
			get { return criteriaSummaryControl1.SelectedCritieriaID; }
		}


		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.butCancel = new System.Windows.Forms.Button();
			this.butOK = new System.Windows.Forms.Button();
			this.criteriaSummaryControl1 = new RandomRat.CriteriaSummaryControl();
			this.SuspendLayout();
			// 
			// butCancel
			// 
			this.butCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.butCancel.Location = new System.Drawing.Point(328, 202);
			this.butCancel.Name = "butCancel";
			this.butCancel.Size = new System.Drawing.Size(65, 23);
			this.butCancel.TabIndex = 8;
			this.butCancel.Text = "Cancel";
			this.butCancel.Click += new System.EventHandler(this.butCancel_Click);
			// 
			// butOK
			// 
			this.butOK.Location = new System.Drawing.Point(256, 202);
			this.butOK.Name = "butOK";
			this.butOK.Size = new System.Drawing.Size(65, 23);
			this.butOK.TabIndex = 7;
			this.butOK.Text = "OK";
			this.butOK.Click += new System.EventHandler(this.butOK_Click);
			// 
			// criteriaSummaryControl1
			// 
			this.criteriaSummaryControl1.Location = new System.Drawing.Point(4, 4);
			this.criteriaSummaryControl1.Name = "criteriaSummaryControl1";
			this.criteriaSummaryControl1.Size = new System.Drawing.Size(396, 192);
			this.criteriaSummaryControl1.TabIndex = 9;
			this.criteriaSummaryControl1.Action += new RandomRat.UserActionHandaler(this.criteriaSummaryControl1_Action);
			// 
			// CriteriaSelector
			// 
			this.AcceptButton = this.butOK;
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.CancelButton = this.butCancel;
			this.ClientSize = new System.Drawing.Size(402, 232);
			this.ControlBox = false;
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.criteriaSummaryControl1,
																		  this.butCancel,
																		  this.butOK});
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.MaximizeBox = false;
			this.Name = "CriteriaSelector";
			this.ShowInTaskbar = false;
			this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
			this.Text = "Load Criteria";
			this.Activated += new System.EventHandler(this.CriteriaSelector_Activated);
			this.ResumeLayout(false);

		}
		#endregion


		private void criteriaSummaryControl1_Action(object sender, RandomRat.UserActionArgs e) {
			if (e.UserAction == UserAction.SelectionMade) {
				selectionMade();
			} else if (e.UserAction == UserAction.DeletedAllCriteria) {
				butOK.Enabled = false;
			}
		}

		private void selectionMade() {
			this.DialogResult = DialogResult.OK;
			this.Close();
		}


		private void butOK_Click(object sender, System.EventArgs e) {
			selectionMade();
		}

		private void butCancel_Click(object sender, System.EventArgs e) {
			this.DialogResult = DialogResult.Cancel;
			this.Close();
		}

		
		private void CriteriaSelector_Activated(object sender, System.EventArgs e) {
			criteriaSummaryControl1.Focus();
		}
	}
}
